package com.symria.server.bo.system;

import java.util.Date;
import java.util.List;

import com.symria.framework.page.Page;
import com.symria.framework.util.HttpHelp;
import com.symria.server.bo.common.CommonService;
import com.symria.server.dao.common.ChannelDao;
import com.symria.server.po.PackDateReport;
import com.symria.server.po.PackInfo;
import com.symria.server.po.UserInfo;
import com.symria.system.constants.ATTSystem;
import com.symria.system.util.SessionHelper;

public class ChannelService extends CommonService{

	private ChannelDao channelDao;
	
	
	public ChannelDao getChannelDao() {
		return channelDao;
	}
	public void setChannelDao(ChannelDao channelDao) {
		this.channelDao = channelDao;
	}
	public UserInfo findUserByName(String userName){
		return channelDao.findUserByName(userName);
	}
	public void updateUserForLogin(UserInfo user){
		updateUserLogin(user);//更新登录用户
		SessionHelper.set(ATTSystem.SESSION_USER, user);//设置session
    }
	private void updateUserLogin(UserInfo user){
		// 记录次数修改
		Integer times =  user.getLoginTimes() == null ? 0 : user.getLoginTimes();
		times++;
		user.setLoginTimes(times);
		// 记录登陆时间
		user.setLoginDate(new Date());
		// 记录登陆ip
		String ip = HttpHelp.getIpAddr();
		
		user.setLoginIp(ip);
		HttpHelp.addCookie(null, ATTSystem.DAYS_TIMES, "/", ATTSystem.COOKIE_NAME, user.getUserName());//设置cookie
		updateObject(user);
	}
	public void searchPackReport(PackDateReport pdr,UserInfo user,Date beginDate,Date endDate,Page page){
		channelDao.searchPackReport(pdr, user, beginDate, endDate, page);
	}
	public List<PackInfo> queryPackInfo(Integer userId){
		return channelDao.queryPackInfo(userId);
	}
	
}
